package com.bs.visitservice.common;

import com.bs.visitservice.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
@ControllerAdvice
public class ExceptionController {
    private final Logger logger = LoggerFactory.getLogger(ExceptionController.class);
    /**
     * 捕获自定义异常
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler
    public Result myHandler(SysException e){
        logger.error("异常",e);
        return Result.build(e.getCode(), e.getMessage());
    }

    /**
     * 捕获全局异常
     * @param e
     * @return
     */
    @ResponseBody
    @ExceptionHandler
    public Result handler(Exception e){
        logger.error("异常",e);
        return Result.build("500", e.getMessage());
    }
}
